import requests
import json

# 替换为你的 DeepSeek API 密钥
API_KEY = 'sk-xgxbqajfxbsfptqumdbsrtiakcisgochhzyltatkcqtarlvq'
API_URL = 'https://api.deepseek.com/v1/chat/completions'

def chat_with_deepseek(prompt):
    headers = {
        'Authorization': f'Bearer {API_KEY}',
        'Content-Type': 'application/json'
    }

    data = {
        "model": "deepseek-chat",  # 替换为你想使用的模型
        "messages": [
            {"role": "user", "content": prompt}
        ]
    }

    response = requests.post(API_URL, headers=headers, data=json.dumps(data))
    if response.status_code == 200:
        return response.json()['choices'][0]['message']['content']
    else:
        return f"Error: {response.status_code}, {response.text}"

def main():
    print("Welcome to the DeepSeek Chat! Type 'exit' to end the conversation.")
    while True:
        user_input = input("You: ")
        if user_input.lower() == 'exit':
            print("Goodbye!")
            break
        response = chat_with_deepseek(user_input)
        print(f"DeepSeek: {response}")

if __name__ == "__main__":
    main()